package Java攻略._3_流式操作._9_查找流的第一个元素;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class _46_查找第一个偶数 {

    public static void main(String[] args) {

        Stream<Integer> integerStream = Stream.of(1, 2, 3, 4, 5);

        List<Integer> integerList = integerStream.filter(n -> n % 2 == 0).collect(Collectors.toList());
        System.out.println(integerList);


        integerStream = Stream.of(1, 2, 3, 4, 5);

        Optional<Integer> first = integerStream.filter(n -> n % 2 == 0).findFirst();
        System.out.println(first);
    }
}
